rm(list = ls())
library(tidyverse)
library(haven)
library(readxl)
library(lfe)
winsorize_x = function(x, cut = 0.001){
cut_point_top <- quantile(x, 1 - cut, na.rm = T)
cut_point_bottom <- quantile(x, cut, na.rm = T)
i = which(x >= cut_point_top)
x[i] = cut_point_top
j = which(x <= cut_point_bottom)
x[j] = cut_point_bottom
return(x)
}
### Unemployment ###############################################################
spf_fcsts_unemp <- read_excel("Replication_Code/01_InData/Individual_UNEMP.xlsx") %>%
select(YEAR, QUARTER, ID, INDUSTRY, UNEMP1, UNEMP2, UNEMP3, UNEMP4, UNEMP5, UNEMP6) %>%
mutate_if(is.character, as.numeric) %>%
arrange(ID, YEAR, QUARTER) %>%
mutate(UNEMP1_lag_1  = lag(UNEMP1, 1L),
UNEMP2_lag_1  = lag(UNEMP2, 1L),
UNEMP3_lag_1  = lag(UNEMP3, 1L),
UNEMP4_lag_1  = lag(UNEMP4, 1L),
UNEMP5_lag_1  = lag(UNEMP5, 1L),
UNEMP6_lag_1  = lag(UNEMP6, 1L),
YEAR_lag_1    = lag(YEAR, 1L),
QUARTER_lag_1 = lag(QUARTER, 1L)) %>%
filter((YEAR_lag_1 == YEAR & QUARTER_lag_1 == QUARTER - 1) |  (YEAR_lag_1 == YEAR - 1 & QUARTER_lag_1 == 4)) %>%
arrange(YEAR, QUARTER, ID) %>%
group_by(YEAR, QUARTER) %>%
mutate(median_prior_lag_1   = ntile(UNEMP6_lag_1, 2L),
quintile_prior_lag_1 = ntile(UNEMP6_lag_1, 5L)) %>%
ungroup()
rm(list=ls())
rm(list=ls())
rm(list=ls())
library(dplyr)
library(haven)
library(data.table)
library(quantreg)
library(lubridate)
library(readr)
library(openxlsx)
library(multiwayvcov)
library(lmtest)
library(texreg)
library(foreign)
data2015<-data.table(read_dta("C:/Users/pkelly6/Dropbox/Motivated beliefs analysts/Unaffiliated/Earn_2015_long.dta"))
Recs<- data.table(read.csv(paste0(datadir,"recs_old.csv")))
datadir <- "/users/pkelly6/Dropbox/Motivated beliefs analysts/"
Recs<- data.table(read.csv(paste0(datadir,"recs_old.csv")))
